const express = require('express');
const mysqlUtil = require('../mysql/mysql-util');
const utilFunc = require("../utilFunc");
const jwtHandle = require("../utilFunc/jwtHandle");
const router = express.Router();

router.get('/', (req, res) =>{
    const data = {
        code: 200,
        content: '',
        message: '首页！'
    }
    res.send(data);
});

router.post('/mens', (req, res) =>{
    const data = utilFunc.getResponseData();
    const headers = req.headers;
    const token = headers['xylo-token'];
    let sql = "SELECT * FROM mens WHERE `public`='1'";
    jwtHandle.getUserIdByjwtVerify(token, (userId) => {
        sql = "SELECT * FROM mens";
    }, (e) => {});
    mysqlUtil.query(sql, (err, result) => {
        if (err) {
            return console.log("查询数据库菜单报错！");
        }
        data.content = utilFunc.treeDataHandle(result);
        res.send(data);
    })
});

module.exports = router;